{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "19df9358-5ee6-46a6-8bd3-b51e0e45995e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://mirrors.aliyun.com/pypi/simple/\n",
      "Requirement already satisfied: tle2czml in /storage/DevEnv/python/py39/lib/python3.9/site-packages (0.3)\n",
      "Requirement already satisfied: pygeoif>=0.7 in /storage/DevEnv/python/py39/lib/python3.9/site-packages (from tle2czml) (1.1.0)\n",
      "Requirement already satisfied: python-dateutil>=2.6.1 in /storage/DevEnv/python/py39/lib/python3.9/site-packages (from tle2czml) (2.8.2)\n",
      "Requirement already satisfied: pytz>=2018.3 in /storage/DevEnv/python/py39/lib/python3.9/site-packages (from tle2czml) (2022.7)\n",
      "Requirement already satisfied: sgp4>=1.4 in /storage/DevEnv/python/py39/lib/python3.9/site-packages (from tle2czml) (2.22)\n",
      "Requirement already satisfied: six>=1.11.0 in /storage/DevEnv/python/py39/lib/python3.9/site-packages (from tle2czml) (1.16.0)\n",
      "Requirement already satisfied: wheel>=0.24.0 in /storage/DevEnv/python/py39/lib/python3.9/site-packages (from tle2czml) (0.38.4)\n",
      "Requirement already satisfied: typing-extensions in /storage/DevEnv/python/py39/lib/python3.9/site-packages (from pygeoif>=0.7->tle2czml) (4.6.3)\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install tle2czml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "adda875c-d9f5-4236-a123-4de0c1eff08e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-10-27T06:35:31.808440+00:00/2023-10-28T06:35:31.808440+00:00\n",
      "2023-10-27T06:35:31.808440+00:00\n",
      "\n",
      "Satellite Name:  BEIDOU 3 G3\n",
      "TLE Epoch:  2023-03-28 19:15:42.665759\n",
      "Orbit time in Minutes:  1436.0028716467425\n",
      "\n",
      "\n",
      "Satellite Name:  BEIDOU 3 G2\n",
      "TLE Epoch:  2023-03-28 22:12:42.892415\n",
      "Orbit time in Minutes:  1436.1084620118097\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import tle2czml\n",
    "tles = '''BEIDOU 3 G3\n",
    "1 45807U 20040A   23087.80257715 -.00000362  00000-0  00000+0 0  9996\n",
    "2 45807   0.8428 319.4828 0006765 332.9703 292.8644  1.00278351 10287\n",
    "BEIDOU 3 G2\n",
    "1 45344U 20017A   23087.92549644 -.00000147  00000-0  00000+0 0  9995\n",
    "2 45344   1.9932   7.5317 0001608  39.8409 191.8663  1.00270978 11478'''\n",
    "czml = tle2czml.tles_to_czml(tles)\n",
    "print(czml)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ecabe1ac-c6cf-4d61-a293-c7d9e2b7e06e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "TLE format error\n\nThe Two-Line Element (TLE) format was designed for punch cards, and so\nis very strict about the position of every period, space, and digit.\nYour line does not quite match.  Here is the official format for line 1\nwith an N where each digit should go, followed by the line you provided:\n\n1 NNNNNC NNNNNAAA NNNNN.NNNNNNNN +.NNNNNNNN +NNNNN-N +NNNNN-N N NNNNN\nISS (ZARYA)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[8], line 19\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mtle2czml\u001b[39;00m\n\u001b[1;32m      2\u001b[0m tles \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'''\u001b[39m\n\u001b[1;32m      3\u001b[0m \u001b[38;5;124mISS (ZARYA)\u001b[39m\n\u001b[1;32m      4\u001b[0m \u001b[38;5;124m1 25544U 98067A   20293.22611972  .00000497  00000-0  17003-4 0  9991\u001b[39m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m     17\u001b[0m \u001b[38;5;124m2 43546  51.6326   6.1225 0002465  18.8688 341.2406 15.83306046129681\u001b[39m\n\u001b[1;32m     18\u001b[0m \u001b[38;5;124m'''\u001b[39m\n\u001b[0;32m---> 19\u001b[0m czml \u001b[38;5;241m=\u001b[39m \u001b[43mtle2czml\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtles_to_czml\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtles\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m     20\u001b[0m \u001b[38;5;28mprint\u001b[39m(czml)\n",
      "File \u001b[0;32m~/DevEnv/python/py39/lib/python3.9/site-packages/tle2czml/tle2czml.py:308\u001b[0m, in \u001b[0;36mtles_to_czml\u001b[0;34m(tles, start_time, end_time, silent)\u001b[0m\n\u001b[1;32m    304\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m    305\u001b[0m \u001b[38;5;124;03mConverts the contents of a TLE file to CZML and returns the JSON as a string\u001b[39;00m\n\u001b[1;32m    306\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m    307\u001b[0m rgbs \u001b[38;5;241m=\u001b[39m Colors()\n\u001b[0;32m--> 308\u001b[0m satellite_array \u001b[38;5;241m=\u001b[39m \u001b[43mread_tles\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtles\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrgbs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    310\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m start_time:\n\u001b[1;32m    311\u001b[0m     start_time \u001b[38;5;241m=\u001b[39m datetime\u001b[38;5;241m.\u001b[39mutcnow()\u001b[38;5;241m.\u001b[39mreplace(tzinfo\u001b[38;5;241m=\u001b[39mpytz\u001b[38;5;241m.\u001b[39mUTC)\n",
      "File \u001b[0;32m~/DevEnv/python/py39/lib/python3.9/site-packages/tle2czml/tle2czml.py:295\u001b[0m, in \u001b[0;36mread_tles\u001b[0;34m(tles, rgbs)\u001b[0m\n\u001b[1;32m    292\u001b[0m raw_tle\u001b[38;5;241m.\u001b[39mappend(line)\n\u001b[1;32m    294\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m i \u001b[38;5;241m%\u001b[39m \u001b[38;5;241m3\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m--> 295\u001b[0m     tle_object \u001b[38;5;241m=\u001b[39m \u001b[43mtwoline2rv\u001b[49m\u001b[43m(\u001b[49m\u001b[43mraw_tle\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mraw_tle\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mwgs72\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    296\u001b[0m     sats\u001b[38;5;241m.\u001b[39mappend(Satellite(raw_tle, tle_object, rgbs\u001b[38;5;241m.\u001b[39mget_next_color()))\n\u001b[1;32m    297\u001b[0m     raw_tle \u001b[38;5;241m=\u001b[39m []\n",
      "File \u001b[0;32m~/DevEnv/python/py39/lib/python3.9/site-packages/sgp4/io.py:165\u001b[0m, in \u001b[0;36mtwoline2rv\u001b[0;34m(longstr1, longstr2, whichconst, opsmode, satrec)\u001b[0m\n\u001b[1;32m    163\u001b[0m     satrec\u001b[38;5;241m.\u001b[39melnum \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(line[\u001b[38;5;241m64\u001b[39m:\u001b[38;5;241m68\u001b[39m])\n\u001b[1;32m    164\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 165\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(error_message\u001b[38;5;241m.\u001b[39mformat(\u001b[38;5;241m1\u001b[39m, LINE1, line))\n\u001b[1;32m    167\u001b[0m line \u001b[38;5;241m=\u001b[39m longstr2\u001b[38;5;241m.\u001b[39mrstrip()\n\u001b[1;32m    169\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;28mlen\u001b[39m(line) \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m69\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[1;32m    170\u001b[0m     line\u001b[38;5;241m.\u001b[39mstartswith(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m2 \u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[1;32m    171\u001b[0m     line[\u001b[38;5;241m7\u001b[39m] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m \u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    179\u001b[0m     line[\u001b[38;5;241m46\u001b[39m] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m\n\u001b[1;32m    180\u001b[0m     line[\u001b[38;5;241m51\u001b[39m] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m \u001b[39m\u001b[38;5;124m'\u001b[39m):\n",
      "\u001b[0;31mValueError\u001b[0m: TLE format error\n\nThe Two-Line Element (TLE) format was designed for punch cards, and so\nis very strict about the position of every period, space, and digit.\nYour line does not quite match.  Here is the official format for line 1\nwith an N where each digit should go, followed by the line you provided:\n\n1 NNNNNC NNNNNAAA NNNNN.NNNNNNNN +.NNNNNNNN +NNNNN-N +NNNNN-N N NNNNN\nISS (ZARYA)"
     ]
    }
   ],
   "source": [
    "import tle2czml\n",
    "tles = '''\n",
    "ISS (ZARYA)\n",
    "1 25544U 98067A   20293.22611972  .00000497  00000-0  17003-4 0  9991\n",
    "2 25544  51.6436  94.7185 0001350  46.8729 126.5595 15.49312821251249\n",
    "KESTREL EYE IIM (KE2M)\n",
    "1 42982U 98067NE  20293.11355452  .00022129  00000-0  15728-3 0  9999\n",
    "2 42982  51.6336   8.5058 0001619 215.9884 144.1006 15.73808685170523\n",
    "DELLINGR (RBLE)\n",
    "1 43021U 98067NJ  20292.66572402  .00020201  00000-0  13900-3 0  9998\n",
    "2 43021  51.6343   8.5926 0000331  53.4398 306.6632 15.74631224166254\n",
    "UBAKUSAT\n",
    "1 43467U 98067NQ  20293.19063114  .00070844  00000-0  29473-3 0  9996\n",
    "2 43467  51.6335   1.3662 0002867   6.9343 353.1700 15.85064344139669\n",
    "CUBERRT\n",
    "1 43546U 98067NU  20292.65915576  .00130902  00000-0  58528-3 0  9997\n",
    "2 43546  51.6326   6.1225 0002465  18.8688 341.2406 15.83306046129681\n",
    "'''\n",
    "czml = tle2czml.tles_to_czml(tles)\n",
    "print(czml)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d3e2441-f137-4aa9-a250-f85ac8230c9b",
   "metadata": {},
   "outputs": [],
   "source": [
    "zoom = \"0-10\"\n",
    "minmax = zoom.split(\"-\",1)\n",
    "print(minmax)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
